package com.fqgj.sentry.common.response;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: yujianfu (mr.vencnet@gmail.com)
 * Date: 16/8/24
 * Time: 上午11:03
 */
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class ApiOutput<T> {

    private Integer code = 200;

    private String msg = "SUCCESS";

    private T data;


    public ApiOutput(T data) {
        this.data = data;
    }

    public ApiOutput() {
    }


    public ApiOutput(String key, T data) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, data);
        this.data = (T) map;
    }

    public ApiOutput(String key, T data, T params) {
        Map<String, Object> map = new HashMap<>();
        map.put(key, data);
        this.data = (T) map;
    }

    public ApiOutput(Integer errorCode, String errorMsg) {
        this.code = errorCode;
        this.msg = errorMsg;
    }


    public static ApiOutput success() {
        return new ApiOutput();
    }

    public Integer getCode() {
        return code;
    }

    public ApiOutput setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMsg() {
        return msg;
    }

    public ApiOutput setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public T getData() {
        return data;
    }

    public ApiOutput setData(T data) {
        this.data = data;
        return this;
    }

}
